package com.bwie.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.pojo.TbOrder;
import com.bwie.pojo.TbUser;
import com.bwie.service.IUSerService;
import com.bwie.service.TbOrderService;
import com.bwie.mapper.TbOrderMapper;
import com.bwie.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
* @author 28242
* @description 针对表【tb_order(订单表)】的数据库操作Service实现
* @createDate 2025-04-22 10:29:18
*/
@Service
public class TbOrderServiceImpl extends ServiceImpl<TbOrderMapper, TbOrder>
    implements TbOrderService{

    @Autowired
    TbOrderMapper tbOrderMapper;

    @Autowired
    RestTemplate restTemplate;
    @Autowired
    IUSerService iuSerService;


    @Override
    public R getOrderById(Integer id) {

        TbOrder tbOrder = tbOrderMapper.selectById(id);
        if (tbOrder==null){
            return R.ERROR(404,"该订单不存在");
        }

        ///获取用户信息
//        String url="http://localhost:9001//user/index/getUserlistByid/"+id;
//        R r = restTemplate.postForObject(url, null, R.class);

        R r = iuSerService.getUserlistByid(tbOrder.getUserId());

        String u = JSON.toJSONString(r.getData());
        TbUser tbUser = JSON.parseObject(u, TbUser.class);

        tbOrder.setUser(tbUser);
        tbUser.setUserPass(null);

        return R.OK(tbOrder);
    }
}




